/*
 * @Copyright: Citylife 2021
 * @Author: shaokui.gu
 * @Date: 2020-12-23 10:29:36
 * @Description: 
 */
import 'package:flutter/material.dart';

// ignore: must_be_immutable
class GestureAvoidDetector extends StatelessWidget {
  final GestureTapCallback onTap;
  final Widget child;
  final HitTestBehavior behavior;
  final int delayTime;
  DateTime lastPopTime;

  GestureAvoidDetector(
      {Key key,
      this.child,
      this.onTap,
      this.behavior = HitTestBehavior.opaque,
      this.delayTime = 200})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        behavior: behavior,
        onTap: () {
          if (lastPopTime == null ||
              DateTime.now().difference(lastPopTime) >
                  Duration(milliseconds: delayTime)) {
            lastPopTime = DateTime.now();
            if (onTap != null) onTap();
          } else {
            debugPrint("CLGestureDetector ignore tap");
          }
        },
        child: child);
  }
}
